home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Controls / Visual Basic Controls.iso / vbcontrol / aals / aals.exe / DISK1 / _SETUP.1 / Vc_demoDlg.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1998-02-27  |  4.9 KB  |  197 lines

  1. // vc_demoDlg.cpp : implementation file
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include "vc_demo.h"
  6. #include "vc_demoDlg.h"
  7.  
  8. #ifdef _DEBUG
  9. #define new DEBUG_NEW
  10. #undef THIS_FILE
  11. static char THIS_FILE[] = __FILE__;
  12. #endif
  13.  
  14. /////////////////////////////////////////////////////////////////////////////
  15. // CAboutDlg dialog used for App About
  16.  
  17. class CAboutDlg : public CDialog
  18. {
  19. public:
  20.     CAboutDlg();
  21.  
  22. // Dialog Data
  23.     //{{AFX_DATA(CAboutDlg)
  24.     enum { IDD = IDD_ABOUTBOX };
  25.     //}}AFX_DATA
  26.  
  27.     // ClassWizard generated virtual function overrides
  28.     //{{AFX_VIRTUAL(CAboutDlg)
  29.     protected:
  30.     virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
  31.     //}}AFX_VIRTUAL
  32.  
  33. // Implementation
  34. protected:
  35.     //{{AFX_MSG(CAboutDlg)
  36.     //}}AFX_MSG
  37.     DECLARE_MESSAGE_MAP()
  38. };
  39.  
  40. CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
  41. {
  42.     //{{AFX_DATA_INIT(CAboutDlg)
  43.     //}}AFX_DATA_INIT
  44. }
  45.  
  46. void CAboutDlg::DoDataExchange(CDataExchange* pDX)
  47. {
  48.     CDialog::DoDataExchange(pDX);
  49.     //{{AFX_DATA_MAP(CAboutDlg)
  50.     //}}AFX_DATA_MAP
  51. }
  52.  
  53. BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
  54.     //{{AFX_MSG_MAP(CAboutDlg)
  55.         // No message handlers
  56.     //}}AFX_MSG_MAP
  57. END_MESSAGE_MAP()
  58.  
  59. /////////////////////////////////////////////////////////////////////////////
  60. // CVc_demoDlg dialog
  61.  
  62. CVc_demoDlg::CVc_demoDlg(CWnd* pParent /*=NULL*/)
  63.     : CDialog(CVc_demoDlg::IDD, pParent)
  64. {
  65.     //{{AFX_DATA_INIT(CVc_demoDlg)
  66.         // NOTE: the ClassWizard will add member initialization here
  67.     //}}AFX_DATA_INIT
  68.     // Note that LoadIcon does not require a subsequent DestroyIcon in Win32
  69.     m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
  70. }
  71.  
  72. void CVc_demoDlg::DoDataExchange(CDataExchange* pDX)
  73. {
  74.     CDialog::DoDataExchange(pDX);
  75.     //{{AFX_DATA_MAP(CVc_demoDlg)
  76.     DDX_Control(pDX, adi, m_adi);
  77.     DDX_Control(pDX, airspeed, m_airspeed);
  78.     DDX_Control(pDX, altitude, m_altitude);
  79.     DDX_Control(pDX, ad, m_ad);
  80.     DDX_Control(pDX, joystick, m_joystick);
  81.     //}}AFX_DATA_MAP
  82. }
  83.  
  84. BEGIN_MESSAGE_MAP(CVc_demoDlg, CDialog)
  85.     //{{AFX_MSG_MAP(CVc_demoDlg)
  86.     ON_WM_SYSCOMMAND()
  87.     ON_WM_PAINT()
  88.     ON_WM_QUERYDRAGICON()
  89.     //}}AFX_MSG_MAP
  90. END_MESSAGE_MAP()
  91.  
  92. /////////////////////////////////////////////////////////////////////////////
  93. // CVc_demoDlg message handlers
  94.  
  95. BOOL CVc_demoDlg::OnInitDialog()
  96. {
  97.     CDialog::OnInitDialog();
  98.  
  99.     // Add "About..." menu item to system menu.
  100.  
  101.     // IDM_ABOUTBOX must be in the system command range.
  102.     ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
  103.     ASSERT(IDM_ABOUTBOX < 0xF000);
  104.  
  105.     CMenu* pSysMenu = GetSystemMenu(FALSE);
  106.     CString strAboutMenu;
  107.     strAboutMenu.LoadString(IDS_ABOUTBOX);
  108.     if (!strAboutMenu.IsEmpty())
  109.     {
  110.         pSysMenu->AppendMenu(MF_SEPARATOR);
  111.         pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
  112.     }
  113.  
  114.     // Set the icon for this dialog.  The framework does this automatically
  115.     //  when the application's main window is not a dialog
  116.     SetIcon(m_hIcon, TRUE);            // Set big icon
  117.     SetIcon(m_hIcon, FALSE);        // Set small icon
  118.     
  119.     // TODO: Add extra initialization here
  120.     m_ad.SetASAltitude(5000.0);
  121.     m_ad.SetASAirspeed(130.0);
  122.     
  123.     return TRUE;  // return TRUE  unless you set the focus to a control
  124. }
  125.  
  126. void CVc_demoDlg::OnSysCommand(UINT nID, LPARAM lParam)
  127. {
  128.     if ((nID & 0xFFF0) == IDM_ABOUTBOX)
  129.     {
  130.         CAboutDlg dlgAbout;
  131.         dlgAbout.DoModal();
  132.     }
  133.     else
  134.     {
  135.         CDialog::OnSysCommand(nID, lParam);
  136.     }
  137. }
  138.  
  139. // If you add a minimize button to your dialog, you will need the code below
  140. //  to draw the icon.  For MFC applications using the document/view model,
  141. //  this is automatically done for you by the framework.
  142.  
  143. void CVc_demoDlg::OnPaint() 
  144. {
  145.     if (IsIconic())
  146.     {
  147.         CPaintDC dc(this); // device context for painting
  148.  
  149.         SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
  150.  
  151.         // Center icon in client rectangle
  152.         int cxIcon = GetSystemMetrics(SM_CXICON);
  153.         int cyIcon = GetSystemMetrics(SM_CYICON);
  154.         CRect rect;
  155.         GetClientRect(&rect);
  156.         int x = (rect.Width() - cxIcon + 1) / 2;
  157.         int y = (rect.Height() - cyIcon + 1) / 2;
  158.  
  159.         // Draw the icon
  160.         dc.DrawIcon(x, y, m_hIcon);
  161.     }
  162.     else
  163.     {
  164.         CDialog::OnPaint();
  165.     }
  166. }
  167.  
  168. // The system calls this to obtain the cursor to display while the user drags
  169. //  the minimized window.
  170. HCURSOR CVc_demoDlg::OnQueryDragIcon()
  171. {
  172.     return (HCURSOR) m_hIcon;
  173. }
  174.  
  175. BEGIN_EVENTSINK_MAP(CVc_demoDlg, CDialog)
  176.     //{{AFX_EVENTSINK_MAP(CVc_demoDlg)
  177.     ON_EVENT(CVc_demoDlg, ad, 1 /* Timer */, OnTimerad, VTS_NONE)
  178.     //}}AFX_EVENTSINK_MAP
  179. END_EVENTSINK_MAP()
  180.  
  181. void CVc_demoDlg::OnTimerad() 
  182. {
  183. //Joystick Inputs
  184.     m_ad.SetCNTLAileron(m_joystick.GetXPos());
  185.     m_ad.SetCNTLElevator(m_joystick.GetYPos());
  186.     m_ad.SetCNTLRudder(m_joystick.GetRPos());
  187.     m_ad.SetCNTLThrottle(m_joystick.GetZPos());
  188.  
  189. //Set Aircraft Instrument Properties
  190.     m_adi.SetAHRoll((float) m_ad.GetASRoll());
  191.     m_adi.SetAHPitch((float) m_ad.GetASPitch());
  192.     m_adi.SetAHHeading((float) m_ad.GetASHeading());
  193.  
  194.     m_airspeed.SetAirspeed((float) m_ad.GetASAirspeed()*0.5925f);  //convert ft/sec to Kts
  195.     m_altitude.SetAltitude((float) m_ad.GetASAltitude());    
  196. }
  197.